package com.example.demo.mybatis.controller;

import com.example.demo.base.ApiCommonCodeEnum;
import com.example.demo.base.Res;
import com.example.demo.mybatis.entity.Person;
import com.example.demo.mybatis.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private PersonService personService;

    @RequestMapping("/findAll")
    public List<Person> findAll(){
        return personService.findAll();
    }

    @RequestMapping("/insert")
    public Res insert(@RequestParam("age") Integer age,@RequestParam("name") String name) {
        Person person = new Person();
//        Map<String,String> map = new HashMap<String, String>();
        if(age == null || "".equals(age) || name == null || "".equals(name)) {
            return Res.noParam();
        }
        person.setAge(age);
        person.setName(name);
        return Res.ok(personService.insert(person));
    }

}
